package org.itboys.mobile.service.mysql.web.reward;

import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.mobile.entity.mysql.reward.CooSellingReward;
import org.itboys.mongodb.service.BaseMySqlService;
import org.itboys.param.PageResult;
import org.itboys.param.ParamUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 作者：zzq
 * 时间：2018/1/30
 * 描述：业绩奖和配置奖
 */
@Service
public class CooSellingRewardService extends BaseMySqlService<CooSellingReward>{
    /**
     *
     * @param request
     * @return
     */
    public PageResult<CooSellingReward> selectReward(HttpServletRequest request){
        Map<String,Object> param= ParamUtil.packageMongoExactParam(request,"type");
        return new PageResult<CooSellingReward>(super.select(param),super.count(param));

    }

    /**
     * 新增
     * @param reward
     */
    public void saveReward(CooSellingReward reward){
        if(reward.getId()==0l){

            super.insert(reward);
        }else{
            super.update(reward);

        }
    }

    /**
     * 查找单个
     * @param rewardId
     * @return
     */
    public CooSellingReward findOne(Long rewardId){
        CooSellingReward reward = null;
        if(LongUtil.isNotZreo(rewardId)){
            reward=super.find(rewardId);
        }else {
            reward=new CooSellingReward();
            reward.setId(0l);
        }
        return reward;
    }
}
